<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2018-11-12
  Time: 23:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="${pageContext.request.contextPath}/statics/hplus/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/statics/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">

    <script src="${pageContext.request.contextPath}/statics/hplus/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/hplus/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/treeview/bootstrap-treeview.min.css">
    <script src="${pageContext.request.contextPath}/statics/treeview/bootstrap-treeview.min.js"></script>
    <script>

        function searcha() {
            var opts = $("#roletb").bootstrapTable("getOptions") ;
            var limit = opts.pageSize ;
            var offset = (opts.pageNumber-1) * limit;
            var username = $("#username").val() ;
            $.post("${pageContext.request.contextPath}/pandian/pandianfenye1",{'username':username,'limit':limit,'offset':offset},function (data) {
                // var mydata = eval("("+data+")") ;
                //重新绑定表格数据
                $("#roletb").bootstrapTable('load',data) ;
            })
        }


        $(function () {
            $("#roletb").bootstrapTable({
                url:'${pageContext.request.contextPath}/pandian/pandianfenye1',
                //设置每页多少条数据
                pageSize:2,
                pageList:[2,4,8,16],
                height:300,
                pageNumber:1,
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                //启用服务器端分页
                sidePagination:'server',
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        username:$("#username").val()
                    };
                    return temp;
                },
                columns:[
                    {
                        field:'danhao',
                        title:'盘点单号'
                    },
                    {
                        field:'dianpuStr',
                        title:'盘点店铺'
                    },
                    {
                        field:'date',
                        title:'盘点日期'
                    },
                    {
                        field:'',
                        title:'盈亏总额'
                    },
                    {
                        field:'banliren',
                        title:'经办人'
                    },
                    {
                        field:'beizhu',
                        title:'备注'
                    },
                    {
                        title:'操作',

                    }

                ]
            }) ;
        }) ;
        var roleid ;
        function tofenpei(id) {
            roleid = id ;
            var a =0 ;
            //弹出对话框
            $("#modal-id").modal('show') ;
            //当以话框加载完成后，才展示树形菜单
            $("#modal-id").on("shown.bs.modal",function(){
                if (++a ==1){
                    $.post('${pageContext.request.contextPath}/role/doFenPen',{'roleid':id},function(data){
                        $("#searchTree").treeview({
                            showCheckbox: true,
                            data: data,
                            onNodeChecked: nodeChecked,
                            onNodeUnchecked: nodeUnchecked
                        }) ;
                    }) ;
                }

            })



        }
        function toadd() {
            $("#modelId").modal("show") ;
        }

        function fenpei() {
            var pmid = "" ;
            //1.
            var cks = $("#searchTree").treeview('getChecked') ;
            $.each(cks,function (i,n) {
                //2.
                pmid = pmid + "-" + n.id ;
            })

            $.post('/rolepermission/grantPermission',{'roleid':roleid,'pmid':pmid},function (data) {

                if (data.msg=="1" ){
                    //关闭对话框
                    $("#modal-id").modal('hide') ;
                }

            })
        }


    </script>

</head>
<body>

<%--<shiro:hasPermission name="user:all">--%>
<%--你好shiro--%>
<%--</shiro:hasPermission>--%>


<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">库存统计</h3>
    </div>
    <div class="panel-body">
        <div class="row">
            <div class="col-sm-6">
                <button onclick="toadd()" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;增加</button>
            </div>
            <div class="col-sm-6">

                <form  class="form-inline pull-right">盘点店铺：
                    <input id="username" type="text" class="form-control">
                    <button class="btn btn-primary" onclick="searcha()" type="button"><span class="glyphicon glyphicon-search"> </span>&nbsp;&nbsp;搜索</button>
                </form>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <table id="roletb"></table>
            </div>
        </div>

    </div>
</div>

<!--增加模态框-->
<div class="modal fade" id="modelId">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="modelTitleId">提示</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save</button>
            </div>
        </div>
    </div>
</div>

<!--分配权限的模态框-->
<div class="modal fade" id="modal-id">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">提示信息</h4>
            </div>
            <div class="modal-body">
                <div id="searchTree"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button onclick="fenpei()" type="button" class="btn btn-primary">分配</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<script>
    var treeData = [{
        text: "Parent 1",
        nodes: [{
            text: "Child 1",
            nodes: [{
                text: "Grandchild 1"
            }, {
                text: "Grandchild 2",
                nodes: [{
                    text: "Grandchild 2-1",
                    nodes: [{
                        text: "Grandchild 2-1-1"
                    }, {
                        text: "Grandchild 2-2-1",
                    }]
                }, {
                    text: "Grandchild 1-2",
                }]
            }]
        }, {
            text: "Child 2",
            nodes: [{
                text: "Grandchild 2-1"
            }, {
                text: "Grandchild 2-2",
            }]
        }]
    }, {
        text: "Parent 2",
        id:'11111'
    }, {
        text: "Parent 3"
    }, {
        text: "Parent 4"
    }, {
        text: "Parent 5"
    }];

    var nodeCheckedSilent = false;

    function nodeChecked(event, node) {
        if (nodeCheckedSilent) {
            return;
        }
        nodeCheckedSilent = true;
        checkAllParent(node);
        checkAllSon(node);
        nodeCheckedSilent = false;
    }

    var nodeUncheckedSilent = false;

    function nodeUnchecked(event, node) {
        if (nodeUncheckedSilent)
            return;
        nodeUncheckedSilent = true;
        uncheckAllParent(node);
        uncheckAllSon(node);
        nodeUncheckedSilent = false;
    }

    //选中全部父节点
    function checkAllParent(node) {
        $('#searchTree').treeview('checkNode', node.nodeId, {
            silent: true
        });
        var parentNode = $('#searchTree').treeview('getParent', node.nodeId);
        if (!("nodeId" in parentNode)) {
            return;
        } else {
            checkAllParent(parentNode);
        }
    }
    //取消全部父节点
    function uncheckAllParent(node) {
        $('#searchTree').treeview('uncheckNode', node.nodeId, {
            silent: true
        });
        var siblings = $('#searchTree').treeview('getSiblings', node.nodeId);
        var parentNode = $('#searchTree').treeview('getParent', node.nodeId);
        if (!("nodeId" in parentNode)) {
            return;
        }
        var isAllUnchecked = true; //是否全部没选中
        for (var i in siblings) {
            if (siblings[i].state.checked) {
                isAllUnchecked = false;
                break;
            }
        }
        if (isAllUnchecked) {
            uncheckAllParent(parentNode);
        }

    }

    //级联选中所有子节点
    function checkAllSon(node) {
        $('#searchTree').treeview('checkNode', node.nodeId, {
            silent: true
        });
        if (node.nodes != null && node.nodes.length > 0) {
            for (var i in node.nodes) {
                checkAllSon(node.nodes[i]);
            }
        }
    }
    //级联取消所有子节点
    function uncheckAllSon(node) {
        $('#searchTree').treeview('uncheckNode', node.nodeId, {
            silent: true
        });
        if (node.nodes != null && node.nodes.length > 0) {
            for (var i in node.nodes) {
                uncheckAllSon(node.nodes[i]);
            }
        }
    }
</script>
</body>
</html>
